package com.weijin.bookborrowmanagesystem.handler;

import com.weijin.bookborrowmanagesystem.common.Result;
import com.weijin.bookborrowmanagesystem.exception.AppException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author WeiJin
 * @Version 1.0
 * @Date 2025/3/13 15:34
 */
@RestControllerAdvice
@Slf4j
public class ExceptionAdvice {
    @ExceptionHandler(AppException.class)
    public Result handlerAppException(AppException e) {
        log.error("[异常信息]：{}", e.getMessage());
        Result<Object> result = new Result<>();
        result.setCode(500);
        result.setMsg(e.getMessage());
        result.setTimestamp(System.currentTimeMillis());
        return result;
    }
}
